﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>预约成功</title>
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
</head>
<body>
    <div> 
        <p>订单提交成功，请您及时付款！</p> 
        <p>订单编号：@ViewBag.OrderCode</p>
        <p>支付交易号：@ViewBag.PayCode</p>
        <p>支付金额：@Math.Round(ViewBag.Price,2) 元</p>
        @*<a id="pay" href="＃">确认支付</a>*@
        <button id="pay" type="button">微信支付</button>

        <!--测试信息-->
        <label id="msg"></label>
    </div>
    <script type="text/javascript">
        function callpay() {
            if (typeof (WeixinJSBridge) == "undefined") {
                if (document.addEventListener) {
                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                }
                else if (document.attachEvent) {
                    document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                }
                //$("#msg").html("附加jsApi事件和监听成功！");
            }
            else {
                //$("#msg").html("开始发起jsApi调用！");
                jsApiCall();
            }
        }

        //调用微信JS api 支付
        function jsApiCall() {
           
            var openId = '@ViewBag.OpenId';
            var total_fee = '@ViewBag.Price';
            var orderId = '@ViewBag.OrderId';
            //$("#msg").html("调用微信jsapi支付，OpenId：" + openId + " 金额：" + total_fee + " 订单号：" + orderId);
            $.ajax({
                url: '@Url.Action("GetPayParameters", "WeChatPay")',
                data: {orderId: orderId, openId: openId },
                type: 'get',
                success: function (data) {
                    //$("#msg").html("服务器返回信息成功！Code:"+data.Code);
                    if(data.Code==1)
                    {
                        //$("#msg").html("发起微信支付请求！");
                        WeixinJSBridge.invoke('getBrandWCPayRequest', JSON.parse(data.Data), function (res) {
                            WeixinJSBridge.log(res.err_msg);
                            //alert(res.err_code + res.err_desc + res.err_msg);
                            //跳转到会员中心
                            //$("#msg").html("支付完成跳转到会员中心！");
                            $("#msg").html("订单支付成功！");
                            location.href = '/wap/member.html';
                        });
                    }
                    else
                    {
                        //$("#msg").html("error.");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $("#msg").html("错误信息："+XMLHttpRequest.status + " " + XMLHttpRequest.readyState + " " + textStatus);
                }
            });
            //获取OpenId
            @*$.ajax({
                url: '@Url.Action("CreateJsApiPay", "example")',
                type: 'get',
                success: function (data) {
                    if (data.Code == 1) {*@
                        //发起支付
                        @*$.get('@Url.Action("GetPayParameters", "example")', new { money: 1, order: '001', openId: '@ViewBag.OpenId' }, function (data) {
                            $("#msg").html("444");
                            WeixinJSBridge.invoke('getBrandWCPayRequest', JSON.parse(data.Data), function (res) {
                                WeixinJSBridge.log(res.err_msg);
                                alert(res.err_code + res.err_desc + res.err_msg);
                            });
                        });*@
            //        }
            //        else {
            //            //alert(data.Msg);
            //            $("#msg").html(data.Msg);
            //        }
            //    }
            //})

            
        }


        //支付
        $("#pay").click(function () {
            //$("#msg").html("支付按钮已点击！");
            $("#msg").html("订单支付中...");
            callpay();
        });
    </script>
</body>
</html>
